{% extends "base.html" %}
{% load i18n bootstrap3 static dv_filters %}

{% block bootstrap3_extra_head %}
    <link rel="stylesheet" href="{% static 'flags/sprite.css' %}" />
{% endblock %}

{% block head_title %}{{ userprofile.get_full_name }}{% endblock %}
{% block content %}
    <div class="panel panel-{{ userprofile.profile.status_class }} vcard">
        <div class="panel-heading">
            <h2 class="panel-title">
                <a href="{{ userprofile.get_absolute_url }}" class="fn">{{ userprofile.get_full_name }}</a>
                {% if userprofile.profile.formation %}
                    <span class="badge pull-right">{{ userprofile.profile.formation_full }} {{ userprofile.profile.formation_icon }}</span>
                {% endif %}
                {% if userprofile.profile.actor %}
                    <span class="badge pull-right">{{ userprofile.profile.actor_inline }} {{ userprofile.profile.actor_icon }}</span>
                {% endif %}
                {% if request.user|inusercantons:userprofile.profile.affiliation_canton or request.user|inusercantons:userprofilecanton %}
                    {% if userprofile.profile.can_login %}
                        <span class="badge pull-right">{{ userprofile.profile.access_level_icon }}</span>
                        {% if request.user|can:"user_can_resend_credentials" %}
                            <a class="badge pull-right" href="{% url 'user-resendcredentials' pk=userprofile.pk %}" title="{% trans "Réinitialiser les données de connexion" %}">
                                <span class="glyphicon glyphicon-envelope" aria-hidden="true" title="{% trans "Réinitialiser les données de connexion" %}"></span>
                            </a>
                        {% endif %}
                    {% else %}
                        {% if request.user|can:"user_can_send_credentials" and request.user.pk != userprofile.pk %}
                            <a class="badge pull-right" href="{% url 'user-sendcredentials' pk=userprofile.pk %}" title="{% trans "Envoyer les données de connexion" %}">
                                <span class="glyphicon glyphicon-envelope" aria-hidden="true" title="{% trans "Envoyer les données de connexion" %}"></span>
                            </a>
                        {% endif %}
                    {% endif %}
                    {% if request.user|can:"user_deletions" and request.user.pk != userprofile.pk and not userprofile.profile.deleted %}
                        <a class="badge pull-right" href="{% url 'user-delete' pk=userprofile.pk %}" title="{% trans "Supprimer" %}">
                            <span class="glyphicon glyphicon-trash" aria-hidden="true" title="{% trans "Supprimer" %}"></span>
                        </a>
                    {% endif %}
                {% endif %}
            </h2>
        </div>

        <div class="panel-body">
        {% comment %}
            <!-- Nav tabs -->
            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation" class="active"><a href="#addr" aria-controls="coord" role="tab" data-toggle="tab">{% trans "Adresse" %}</a></li>
                <li role="presentation"><a href="#contacts" aria-controls="contacts" role="tab" data-toggle="tab">{% trans "Contacts" %}</a></li>
                {% if userprofile.profile.iban or userprofile.profile.social_security %}
                    <li role="presentation"><a href="#administrativia" aria-controls="administrativia" role="tab" data-toggle="tab">{% trans "Administratif" %}</a></li>
                {% endif %}
                <li role="presentation"><a href="#defi" aria-controls="defi" role="tab" data-toggle="tab">{% trans "Défi" %}</a></li>

                {% if userprofile.profile.comments %}
                    <li role="presentation"><a href="#notes" aria-controls="notes" role="tab" data-toggle="tab">{% trans "Notes" %}</a></li>
                {% endif %}
            </ul>
        {% endcomment %}

            <!-- Tab panes -->
            <div>
                <div role="tabpane" class="tab-pane active adr" id="addr">
                    <dl class="dl-horizontal">
                        <dt>{% trans "Nom" %}</dt>
                            <dd>{{ userprofile.get_full_name }}</dd>
                        {% if userprofile.profile.has_address %}
                          <dt>{% trans "Adresse" %}</dt>
                            <dd>
                                <div class="street-address">{{ userprofile.profile.address_street }} {{ userprofile.profile.address_no }}</div>
                                <div>
                                    <span class="postal-code">{{ userprofile.profile.address_zip }}</span> <span class="locality">{{ userprofile.profile.address_city }}</span>
                                    {% if userprofile.profile.address_canton %}
                                    ({{ userprofile.profile.address_canton }})
                                    {% endif %}
                                </div>
                            </dd>
                        {% endif %}
                    </dl>
                </div>
                <div role="tabpane" class="tab-pane" id="contacts">
                    <dl class="dl-horizontal">
                        {% if userprofile.profile.birthdate %}
                            <dt>{% trans "Date de naissance" %}</dt>
                                <dd>{{ userprofile.profile.birthdate|date }} ({% blocktrans with age=userprofile.profile.age %}{{ age }} ans{% endblocktrans %})</dd>
                        {% endif %}
                        {% if userprofile.email %}
                            <dt>{% trans "Email" %}</dt>
                                <dd><a class="email" href="mailto:{{ userprofile.profile.mailtolink|urlencode }}">{{ userprofile.email }}</a></dd>
                        {% endif %}
                        {% if userprofile.profile.natel %}
                            <dt>{% trans "Natel" %}</dt>
                                <dd>{{ userprofile.profile.natel|tel_link }}</dd>
                        {% endif %}
                        {% if userprofile.profile.phone %}
                            <dt>{% trans "Téléphone" %}</dt>
                                <dd>{{ userprofile.profile.phone|tel_link }}</dd>
                        {% endif %}
                    </dl>
                </div>
                {% if userprofile.profile.is_paid_staff %}
                  <div role="tabpane" class="tab-pane" id="administrativia">
                    <dl class="dl-horizontal">
                        {% if userprofile.profile.nationality %}
                            <dt>{% trans "Nationalité" %}</dt>
                                <dd>
                                    <span class="{{ userprofile.profile.nationality.flag_css }}"
                                        aria-label="{% blocktrans with country_code=userprofile.profile.nationality.name %}Drapeau de {{ country_code }}{% endblocktrans %}"></span>
                                    {{ userprofile.profile.nationality.name }}
                                </dd>
                        {% endif %}
                        {% if userprofile.profile.work_permit %}
                            <dt>{% trans "Permis de travail" %}</dt>
                                <dd>{{ userprofile.profile.work_permit }}</dd>
                        {% endif %}
                        {% if userprofile.profile.tax_jurisdiction %}
                            <dt>{% trans "Lieu d’imposition" %}</dt>
                                <dd>{{ userprofile.profile.tax_jurisdiction }}</dd>
                        {% endif %}
                        {% if userprofile.profile.bank_name %}
                            <dt>{% trans "Nom de la banque" %}</dt>
                                <dd>{{ userprofile.profile.bank_name }}</dd>
                        {% endif %}
                        {% if userprofile.profile.iban %}
                            <dt>{% trans "N° IBAN" %}</dt>
                                <dd><span style="font-family: monospace">{{ userprofile.profile.iban_nice }}</span></dd>
                        {% endif %}
                        {% if userprofile.profile.employee_code %}
                            <dt>{% trans "N° d’employé Crésus" %}</dt>
                                <dd><span style="font-family: monospace">{{ userprofile.profile.employee_code }}</span></dd>
                        {% endif %}
                        {% if userprofile.profile.social_security %}
                            <dt>{% trans "N° AVS" %}</dt>
                                <dd><span style="font-family: monospace">{{ userprofile.profile.social_security }}</span></dd>
                        {% endif %}
                        {% if userprofile.profile.marital_status %}
                            <dt>{% trans "État civil" %}</dt>
                                <dd>{{ userprofile.profile.marital_status_full }}</dd>
                        {% endif %}
                    </dl>
                  </div>
                {% endif %}
                <div role="tabpane" class="tab-pane" id="defi">
                    <dl class="dl-horizontal">
                      {% if userprofile.profile.is_paid_staff %}
                        {% if userprofile.profile.formation %}
                            <dt>{% trans "Formation" %}</dt><dd>{{ userprofile.profile.formation_full }}
                            {% if userprofile.profile.formation_firstdate %}
                            <br/>{% trans "Première formation : " %}{{ userprofile.profile.formation_firstdate }}
                            {% endif %}
                            {% if userprofile.profile.formation_lastdate %}
                            <br/>{% trans "Dernière formation : " %}{{ userprofile.profile.formation_lastdate }}
                            {% endif %}</dd>
                        {% endif %}
                        {% if userprofile.profile.actor %}
                            <dt>{% trans "Intervenant" %}</dt><dd>{{ userprofile.profile.actor_for.all|join:'<br />' }}</dd>
                        {% endif %}
                      {% endif %}
                        {% if userprofile.profile.status > 0 %}
                        <dt>{% trans "État" %}</dt>
                            <dd class="text-{{ userprofile.profile.status_class }}">
                                    {{ userprofile.profile.status_icon }}
                                    {{ userprofile.profile.status_full }}
                                    {% if userprofile.profile.status_updatetime %}
                                        ({% trans "Dernière mise à jour : " %}{{ userprofile.profile.status_updatetime }})
                                    {% endif %}
                            </dd>
                        {% endif %}
                      {% if userprofile.profile.is_paid_staff %}
                        {% if userprofile.profile.bagstatus > 0 %}
                            <dt>{% trans "Sac Défi Vélo" %}</dt>
                                <dd>
                                        {{ userprofile.profile.bagstatus_icon }}
                                        {{ userprofile.profile.bagstatus_full }}
                                        {% if userprofile.profile.bagstatus_updatetime %}
                                            ({% trans "Dernière mise à jour: " %}{{ userprofile.profile.bagstatus_updatetime }})
                                        {% endif %}
                                </dd>
                        {% endif %}
                        {% if userprofile.profile.pedagogical_experience %}
                            <dt>{% trans "Exp. pédagogique" %}</dt><dd>{{ userprofile.profile.pedagogical_experience }}</dd>
                        {% endif %}
                        <dt>{% trans "Cours samaritain" %}</dt><dd><span class="glyphicon glyphicon-{% if userprofile.profile.firstmed_course %}check{% else %}unchecked{% endif %}"></span> {{ userprofile.profile.firstmed_course_comm }}</dd>
                      {% endif %}
                    </dl>
                </div>
                    <div role="tabpane" class="tab-pane" id="cantons">
                        <dl class="dl-horizontal">
                        {% if userprofile.profile.is_paid_staff %}
                          {% if userprofile.profile.affiliation_canton %}
                            <dt>{% trans "Canton d’affiliation" %}</dt>
                            <dd>{{ userprofile.profile.affiliation_canton|canton_abbr:False }}</dd>
                          {% endif %}
                          {% if userprofile.profile.activity_cantons %}
                            <dt>{% trans "Défi Vélo Mobile" %}</dt>
                            <dd>{{ userprofile.profile.activity_cantons|cantons_abbr:False|join:"<br />" }}
                            </dd>
                          {% endif %}
                        {% endif %}
                        {% if userprofile.profile.can_login %}
                            <dt>{% trans "Niveau d’accès" %}</dt>
                            <dd>{{ userprofile.profile.access_level_icon }} {{ userprofile.profile.access_level }} </dd>
                        {% endif %}
                        {% if userprofile.profile.managed_cantons %}
                            <dt>{% trans "Cantons gérés" %}</dt>
                            <dd>{{ userprofile.profile.managed_cantons|cantons_abbr:False|join:"<br />" }}</dd>
                        {% endif %}
                        {% if userprofile.managed_organizations %}
                            <dt>{% trans "Établissements" %}</dt>
                            <dd>{% for orga in userprofile.managed_organizations.all %}
                                  <a href="{% url 'organization-detail' pk=orga.pk %}">{{ orga.name }}</a> ({{ orga.address_canton|canton_abbr:False }})
                                  {% if not forloop.last %}</br>{% endif %}
                                {% endfor %}
                            </dd>
                        {% endif %}
                        </dl>
                    </div>
                    <div role="tabpane" class="tab-pane" id="languages">
                        <dl class="dl-horizontal">
                        {% if userprofile.profile.language %}
                            <dt>{% trans "Langue" %}</dt>
                            <dd>{{ userprofile.profile.language_verb }}</dd>
                        {% endif %}
                        {% if userprofile.profile.languages_challenges %}
                            <dt>{% trans 'Prêt à animer en' %}</dt>
                            <dd>{{ userprofile.profile.languages_challenges_text }}</dd>
                        {% endif %}
                        </dl>
                    </div>
                {% if request.user|can:'user_crud_dv_private_fields' and userprofile.profile.comments %}
                    <div role="tabpane" class="tab-pane panel panel-danger" id="notes">
                        <div class="panel-heading">{% trans "Remarques privées" %}</div>
                        <div class="panel-body">
                        {{ userprofile.profile.comments|linebreaksbr }}
                        </div>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>
    {% buttons %}
    <div class="hidden-print">
        {% if request.user.pk == userprofile.pk or request.user|can:"cantons_all" or request.user|can:"user_edit_other" and request.user|inusercantons:userprofile.profile.affiliation_canton or request.user|can:"user_edit_other" and request.user|inusercantons:userprofilecanton %}
            <a class="btn btn-primary pull-right" href="{% url 'user-update' pk=userprofile.pk %}{% if return_url %}?returnUrl={{ return_url|urlencode }}{% endif %}{% if return_url and return_label %}&returnLabel={{ return_label|urlencode }}{% elif return_label %}?returnLabel={{ return_label|urlencode }}{% endif %}">
                <span class="glyphicon glyphicon-pencil" aria-hidden="true" title="{% trans "Éditer" %}"></span>
                {% trans "Éditer" %}
            </a>
        {% endif %}
        {% if request.user.pk != userprofile.pk and userprofile.profile.can_login and request.user|can:"user_set_role" or request.user|can:"assign_only_coordinator_role" and profile_is_coordinator or not user_has_a_role %}
            <a class="btn btn-warning pull-right" href="{% url 'user-assign-role' pk=userprofile.pk %}">
              <span class="glyphicon glyphicon-lock" aria-hidden="true" title="{% trans "Modifier le niveau d’accès" %}"></span>
              {% if profile_is_coordinator %}{% trans "Modifier les établissements gérés" %}
              {% else %}{% trans "Modifier le niveau d’accès" %}{% endif %}
            </a>
        {% endif %}
        {% if request.user|can:'user_view_list' %}
            {% trans "Retour à la liste des utilisateurs" as default_return_label %}
            <a class="btn btn-default" href="{% if return_url %}{{ return_url }}{% else %}{% url 'user-list' %}{% endif %}">{{ return_label|default:default_return_label }}</a>
        {% endif %}
    {% endbuttons %}
    {% buttons %}
        {% if request.user|can:"user_create" %}
            <br />
            <a class="btn btn-primary pull-right" href="{% url 'user-create' %}">
                <span class="glyphicon glyphicon-user" aria-hidden="true"></span>
                {% trans "Nouvel utilisateur" %}
            </a>
        {% endif %}
    </div>
    {% endbuttons %}
{% endblock %}
